//
//  BLWashCollectionViewCell.m
//  blanket
//
//  Created by Mac on 2017/12/7.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLWashCollectionViewCell.h"
#import "STAutoAddView.h"
#define cellWith (UIScreenWidth - 10 - 90 - 10)/2
@interface BLWashCollectionViewCell()
@property(nonatomic, strong) UIImageView                     *bannerImageView;
@property(nonatomic, strong) STLabel                     *titleLable;
@property(nonatomic, strong) STLabel                     *priceLable;

@end
@implementation BLWashCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    
    self.bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cellWith, 70)];
    self.bannerImageView.image = [UIImage imageNamed:@"banner1"];
    self.bannerImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.bannerImageView.clipsToBounds = YES;
    [self addSubview:self.bannerImageView];
    
    self.titleLable= [[STLabel alloc] initWithFrame:CGRectMake(10, self.bannerImageView.bottom, cellWith - 20, 20)
                                                     text:@"床单1.2"
                                                textColor:BL_secendTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.titleLable];
    
    self.priceLable= [[STLabel alloc] initWithFrame:CGRectMake(10, self.titleLable.bottom, cellWith - 20, 20)
                                               text:@"单价:￥47"
                                          textColor:BL_redColor
                                               font:13
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.priceLable];
    self.priceLable.attributedText = [self.priceLable.text st_convertAttributeStringWithKeyWord:@"价格:" attributes:@{NSForegroundColorAttributeName:BL_secendTextColor}];
    
    STLabel * numLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.priceLable.bottom, 35, 20)
                                                   text:@"数量:"
                                                textColor:BL_secendTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:numLable];
    
    self.autoAddView = [[STAutoAddView alloc] initWithFrame:CGRectMake(numLable.right, self.priceLable.bottom, 60, 20)];
    [self addSubview:self.autoAddView];
    
    self.addButton = [[STButton alloc] initWithFrame:CGRectMake(0,numLable.bottom + 10, 80, 25)
                                                     title:@"加入购物车"
                                                titleColor:[UIColor whiteColor]
                                                 titleFont:13
                                              cornerRadius:3
                                           backgroundColor:BL_BlueBackGroundColor
                                           backgroundImage:nil
                                                     image:nil];
    self.addButton.centerX = cellWith/2;
    self.addButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self addSubview:self.addButton];
}
- (void)setModel:(BLWashModel *)model{
    _model = model;
    [self.bannerImageView sd_setImageWithURL:[NSURL URLWithString:model.img_url] completed:nil];
    
    self.titleLable.text = model.name;
    
    self.autoAddView.titleLable.text = model.num;
    self.priceLable.text = [NSString stringWithFormat:@"单价:￥%@",model.price];
    self.priceLable.attributedText = [self.priceLable.text st_convertAttributeStringWithKeyWord:@"价格:" attributes:@{NSForegroundColorAttributeName:BL_secendTextColor}];
}
@end
